package com.gc.controller.courseServlet;

import com.gc.entity.Course;
import com.gc.repository.CourseRepository;
import com.gc.repository.impl.CourseRepositoryImpl;
import com.gc.util.result.R;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "courseFindById", value = "/courseFindById" )
public class courseFindById extends HttpServlet {
    CourseRepository courseRepository = new CourseRepositoryImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Gson gson = new Gson();
        Long id = Long.valueOf(request.getParameter("id"));
        Course course = courseRepository.FindById(id);
        System.out.println("测试根据id查找教师");
        System.out.println(course);
        response.getWriter().write(gson.toJson(R.ok().data(course)));
    }
}
